<template>
	<view class="becomeAMerchant">
		<u-form :model="form" ref="uForm">
			<u-form-item>
				<label>店名</label>
				<u-input v-model="form.sName" />
			</u-form-item>
			<u-form-item>
				<label>法定代表人</label>
				<u-input v-model="form.sLegalRepresentaive" />
			</u-form-item>
			<u-form-item>
				<label>身份证</label>
				<u-input v-model="form.sIdentityCard"/>
			</u-form-item>
			<u-form-item>
				<label>联系号码</label>
				<u-input v-model="form.sPhone" />
			</u-form-item>
			<u-form-item>
				<label>地址</label>
				<u-input v-model="form.sAddress" />
			</u-form-item>
		</u-form>
		<label>营业执照副本</label>
<!-- 		<u-upload 
		ref="uUpload" 
		:action="action" 
		:auto-upload="false"
		:max-count="1"
		>
		</u-upload>
		<u-image v-if="form.fileImg" width="100%" height="400rpx" :src="form.fileImg"></u-image>
		<u-button class="btn" @click="submit" :type="btnType">提交</u-button> -->
		<label>营业执照副本</label>
		<u-upload :action="action" @on-success="onSuccess" :file-list="fileList" :max-count="1"></u-upload>
		<!-- <u-image v-if="form.sBusinessLicense" width="100%" height="400rpx" :src="form.sBusinessLicense"></u-image> -->
		<u-button class="btn" @click="save" :type="btnType">申请</u-button>
	</view>
</template>

<script>
	export default {
		data() 
		{
			return {
				form:{
					sUid:'',
					sName:'',
					sLegalRepresentaive:'',
					sIdentityCard:'',
					sPhone:'',
					sAddress:'',
					sAvatar:'',
					sAuthority:0,
				},
				fileList:'',
				action:'http://localhost:8881/shop/upload',
				btnType:'warning',
				btn:{
					ok:'primary',
					no:'warning'
				}
			}
		},
		onLoad() 
		{
			if(this.sAvatar !== ''
			&& this.form.sName !== '' 
			&& this.form.sLegalRepresentaive !== '' 
			&& this.form.sIdentityCard !== '' 
			&& this.form.sPhone !== '' 
			&& this.form.sAddress !== ''
			)
			{
				this.btnType = this.btn.ok
			}
			else
			{
				this.btnType = this.btn.no
			}
		},
		watch:
		{
			form:{
				handler(newValue, oldValue) 
				{
					if(newValue.sAvatar !== '' 
					&& newValue.sName !== '' 
					&& newValue.sLegalRepresentaive !== '' 
					&& newValue.sIdentityCard !== '' 
					&& newValue.sPhone !== '' 
					&& newValue.sAddress !== ''
					)
					{
						this.btnType = this.btn.ok
					}
					else
					{
						this.btnType = this.btn.no
					}
				},
				deep:true
			}
		},
		methods: {
			async save()
			{
				console.log(1111);
				this.form.sUid = this.vuex_person.uId
				let res = await this.$u.api.getShop(this.form)
				console.log(res);
			},
			onSuccess(data, index, lists, name)
			{
				this.form.sAvatar = data
			}
		}
	}
</script>

<style lang="scss">
	.becomeAMerchant
	{
		padding: 0 40rpx;
		padding-bottom: 50rpx;
		.btn
		{
			display: block;
			margin-top: 50rpx;
		}
	}
</style>
